#ifndef _sst16550_h_
#define _sst16550_h_ 1
/**HEADER********************************************************************
* 
* Copyright (c) 2008-2009 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 2004-2008 Embedded Access Inc.;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: serl_st16550.h$
* $Version : 3.5.1.0$
* $Date    : Feb-24-2010$
*
* Comments:
* 
*   This include file is used to provide information needed by
*   an application program using a 16550 compatible UART.
*
*END*********************************************************************/


/*--------------------------------------------------------------------------*/
/*
**                    CONSTANT DEFINITIONS
*/

/* Standard parity definitions */
#define IO_SERIAL_NO_PARITY    1
#define IO_SERIAL_EVEN_PARITY  2
#define IO_SERIAL_ODD_PARITY   3

/* Standard stop bit definitions */
#define IO_SERIAL_1_STOP_BIT    1
#define IO_SERIAL_1_5_STOP_BITS 2
#define IO_SERIAL_2_STOP_BITS   3

/* IO Mode */
#define IO_SERIAL_INT_MODE_POLLED    0
#define IO_SERIAL_INT_MODE_INTERRUPT 1


/*
** I/O Initialization error codes
*/

#define ST16550_IO_INVALID_CHANNEL        (0x10000)

/*
** ST16550 SERIAL INIT STRUCT
** 
** This structure defines what the UART initialization record contains
*/
typedef struct st16550_serial_init_struct
{
   /* The com port address */
   pointer   COM_PORT_ADDRESS;

   /* The serial I/O queue size to use to buffer incoming and outgoing
   ** data.
   */
   _mqx_uint QUEUE_SIZE;

   /* The baud rate for the channel */
   uint_32   BAUD_RATE;

   /* The number of bits in a character */
   _mqx_uint BITS_PER_CHARACTER;
   
   /* The parity to initialize the channel to */
   _mqx_uint PARITY;
   
   /* The number of stop bits */
   _mqx_uint STOP_BITS;

   /* The com ports vector number */
   _mqx_uint VECTOR;

   /* The Clock speed to the uart */
   uint_32   CLOCK_SPEED;

   /*
   ** Some boards may need extra interrupt manipulation 
   */

   /* The address of function to enable interrupts */
   void (_CODE_PTR_ INT_ENABLE)(_mqx_uint);

   /* The address of function to disable interrupts */
   void (_CODE_PTR_ INT_DISABLE)(_mqx_uint);

   /*
   ** The address of function to clear interrupts at the
   ** end of the isr
   */
   void (_CODE_PTR_ INT_CLEAR)(_mqx_uint);

} ST16550_SERIAL_INIT_STRUCT, _PTR_ ST16550_SERIAL_INIT_STRUCT_PTR;


/*
** ST16550_SERIAL_INFO_STRUCT
** Run time state information for the serial channel
*/
typedef struct st16550_serial_info_struct
{
   /* The address of the 16652 uart registers */
   volatile ST16550_UART_STRUCT _PTR_     UART_PTR;
   
   /* The vector number which the uart will interrupt on */
   _mqx_uint                   VECTOR;

   /* Current initialized values */
   ST16550_SERIAL_INIT_STRUCT  INIT;

   /* The previous interrupt handler and data for the UART */
   void          (_CODE_PTR_ OLD_ISR)(pointer);
   void          (_CODE_PTR_ OLD_ISR_EXCEPTION_HANDLER)(_mqx_uint, _mqx_uint,
      pointer, pointer);
   pointer                   OLD_ISR_DATA;

   uint_32                   CONTROL_BITS;
   uint_32                   CURRENT_CONFIGURATION;
   uint_32                   FIFO_CONTROL_REG;
   uint_32                   INT_MODE;
   
   /* Statistical information */
   uint_32                   INTERRUPTS;
   uint_32                   RX_DROPPED_INPUT;
   uint_32                   RX_GOOD_CHARS;
   uint_32                   RX_CHARS;
   uint_32                   TX_CHARS;
   uint_32                   RX_PARITY_ERRORS;
   uint_32                   RX_FRAMING_ERRORS;
   uint_32                   RX_OVERRUNS;
   uint_32                   RX_BREAKS;

} ST16550_SERIAL_INFO_STRUCT, _PTR_ ST16550_SERIAL_INFO_STRUCT_PTR;


/*--------------------------------------------------------------------------*/
/*
**                        FUNCTION PROTOTYPES
*/

#ifdef __cplusplus
extern "C" {
#endif

/* Polled driver functions */
extern uint_32 _st16550_serial_polled_install(char_ptr, pointer, _mqx_uint);

/* Interrupt driver functions */
extern uint_32 _st16550_serial_int_install(char_ptr, pointer, _mqx_uint);

#ifdef __cplusplus
}
#endif

#endif
/* EOF */
